# -*- coding: utf-8 -*-
"""
@Time    : 2024/7/8 19:01 
@Author  : ZhangShenao 
@File    : search_engine_base.py 
@Desc    : 搜索引擎抽象父类
"""
from abc import ABC


class SearchEngineBase(ABC):
    """搜索引擎的抽象父类"""

    def __init__(self):
        """构造函数"""
        pass

    def add_corpus_file(self, file_path: str):
        """将一个语料文件添加到索引中"""
        with open(file_path, 'r') as f:
            text = f.read()
            self.process_corpus(file_path, text)

    def process_corpus(self, corpus_id: str, text: str):
        """
        处理语料,交由子类实现
        :param corpus_id: 语料ID
        :param text: 语料文本内容
        """

        raise NotImplementedError

    def search(self, query: str) -> list[str]:
        """
        搜索,交由子类实现
        :param query: 查询关键词
        :return: 关键词所在的语料ID列表
        """
        raise NotImplementedError
